﻿using JinfuyuanProject.Entity;
using JinfuyuanProject.Service;
using JinfuyuanProject.Service.Interface;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JinfuyuanProject.Controllers
{
    public class ServiceTaskController : Controller
    {
        private readonly IServiceDoService _servicesDoService;

        // GET: ServiceTask
        public ServiceTaskController(IServiceDoService servicesDoService)
        {
            _servicesDoService = servicesDoService;
        }
        #region 页面
        public ActionResult Index()
        {
            return View();
        }



        public ActionResult ServiceDo()
        {
            return View();
        }
        #endregion

        #region 接口
        public JsonResult DataList(int page = 1, int limit = 10, int? serviceType = null, string filterDate = null)
        {
            ServicesFilter filter = new ServicesFilter
            {
                page = page,
                limit = limit,
                ServiceType = serviceType,
                FilterDate = filterDate
            };

            var result = _servicesDoService.ListData(filter);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult ConfirmService(int id)   //服务确认
        {
            var result = _servicesDoService.ConfirmService(id);
            return Json(new { success = result, message = result ? "操作成功" : "操作失败" }, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult AdjustServiceTime(int id, string newTime)
        {
            DateTime adjustedTime;
            if (!DateTime.TryParse(newTime, out adjustedTime))
            {
                return Json(new { success = false, message = "时间格式不正确" }, JsonRequestBehavior.AllowGet);
            }

            var result = _servicesDoService.AdjustServiceTime(id, adjustedTime);
            return Json(new
            {
                success = result,
                message = result ? "时间调整成功" : "时间调整失败"
            }, JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}
